package org.example.codegenerate.model;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
@Slf4j
public class OnlineParameter {
        //private static final Logger q = LoggerFactory.getLogger(org.jeecgframework.codegenerate.a.a.class);
        private static final String r = "jeecg/jeecg_database";
        private static final String s = "jeecg/jeecg_config";
        private static ResourceBundle bundle = getResource("jeecg/jeecg_database");
        private static ResourceBundle resourceBundle;
        public static String dbType;
        public static String dbDriver;
        public static String jdbcConnectUrl;
        public static String userName;
        public static String passWord;
        public static String CWORKSPACEJEECG;
        public static String COMJEECG;
        public static String SRC;
        public static String WebRoot;
        public static String CODETEMPLATE;
        public static boolean k;
        public static String DBTABLEID;
        public static String m;//跟踪的时候，在onetable的时候，是4
        public static String n;//跟踪的时候，在onetable的时候，是1
        public static String o;
        public static String p;//跟踪的时候，在onetable的时候，是1

        public OnlineParameter() {
        }

        private static ResourceBundle getResource(String var0) {
            PropertyResourceBundle propertyResourceBundle = null;
            BufferedInputStream bufferedInputStream = null;
            String var3 = System.getProperty("user.dir") + File.separator + "config" + File.separator + var0 + ".properties";

            try {
                bufferedInputStream = new BufferedInputStream(new FileInputStream(var3));
                propertyResourceBundle = new PropertyResourceBundle(bufferedInputStream);
                bufferedInputStream.close();
                if (propertyResourceBundle != null) {
                    log.info(" JAR方式部署，通过config目录读取配置：" + var3);
                }
            } catch (IOException var13) {
                ;
            } finally {
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (IOException var12) {
                        var12.printStackTrace();
                    }
                }

            }

            return propertyResourceBundle;
        }

        private void n() {
        }

        public static final String getCworkspaceJeecg() {
            return bundle.getString("diver_name");
        }

        public static final String getCodeTemplate() {
            return bundle.getString("url");
        }

        public static final String getResource() {
            return bundle.getString("username");
        }

        public static final String getPassword() {
            return bundle.getString("password");
        }

        public static final String getDataBaseName() {
            return bundle.getString("database_name");
        }

        public static final boolean f() {
            String var0 = resourceBundle.getString("db_filed_convert");
            return !var0.toString().equals("false");
        }

        private static String getBusinessPackage() {
            return resourceBundle.getString("bussi_package");
        }

        private static String getTemplatepath() {
            return resourceBundle.getString("templatepath");
        }

        public static final String getSourceRootPackage() {
            return resourceBundle.getString("source_root_package");
        }

        public static final String h() {
            return resourceBundle.getString("webroot_package");
        }

        public static final String getDbtableid() {
            return resourceBundle.getString("db_table_id");
        }

        public static final String j() {
            return resourceBundle.getString("page_filter_fields");
        }

        public static final String k() {
            return resourceBundle.getString("page_search_filed_num");
        }

        public static final String l() {
            return resourceBundle.getString("page_field_required_num");
        }

        public static String getProjectPath() {
            String var0 = resourceBundle.getString("project_path");
            if (var0 != null && !"".equals(var0)) {
                CWORKSPACEJEECG = var0;
            }

            return CWORKSPACEJEECG;
        }

        /*public static void getCworkspaceJeecg(String projectPath) {
            CWORKSPACEJEECG = projectPath;
        }*/
        public static void setCworkspaceJeecg(String projectPath) {
            CWORKSPACEJEECG = projectPath;
        }
        public static void getCodeTemplate(String templatePath) {
            CODETEMPLATE = templatePath;
        }

        static {
            if (bundle == null) {
                log.debug("通过class目录加载配置文件 jeecg/jeecg_database");
                bundle = ResourceBundle.getBundle("jeecg/jeecg_database");
            }

            resourceBundle = getResource("jeecg/jeecg_config");
            if (resourceBundle == null) {
                log.debug("通过class目录加载配置文件 jeecg/jeecg_config");
                resourceBundle = ResourceBundle.getBundle("jeecg/jeecg_config");
            }

            dbType = "mysql";
            dbDriver = "com.mysql.jdbc.Driver";
            jdbcConnectUrl = "jdbc:mysql://localhost:3306/jeecg-boot?useUnicode=true&characterEncoding=UTF-8";
            userName = "root";
            passWord = "root";
            CWORKSPACEJEECG = "getResource:/workspace/jeecg";
            COMJEECG = "com.jeecg";
            SRC = "src";
            WebRoot = "WebRoot";
            CODETEMPLATE = "/jeecg/code-template/";
            k = true;
            m = "4";
            n = "3";
            p = "1";
            dbDriver = getCworkspaceJeecg();
            jdbcConnectUrl = getCodeTemplate();
            userName = getResource();
            passWord = getPassword();
            SRC = getSourceRootPackage();
            WebRoot = h();
            COMJEECG = getBusinessPackage();
            CODETEMPLATE = getTemplatepath();
            CWORKSPACEJEECG = getProjectPath();
            DBTABLEID = getDbtableid();
            k = f();
            o = j();
            n = k();
            if (jdbcConnectUrl.indexOf("mysql") < 0 && jdbcConnectUrl.indexOf("MYSQL") < 0) {
                if (jdbcConnectUrl.indexOf("oracle") < 0 && jdbcConnectUrl.indexOf("ORACLE") < 0) {
                    if (jdbcConnectUrl.indexOf("postgresql") < 0 && jdbcConnectUrl.indexOf("POSTGRESQL") < 0) {
                        if (jdbcConnectUrl.indexOf("sqlserver") >= 0 || jdbcConnectUrl.indexOf("sqlserver") >= 0) {
                            dbType = "sqlserver";
                        }
                    } else {
                        dbType = "postgresql";
                    }
                } else {
                    dbType = "oracle";
                }
            } else {
                dbType = "mysql";
            }

            SRC = SRC.replace(".", "/");
            WebRoot = WebRoot.replace(".", "/");
        }
    }

